﻿
@{
    Layout = null;
}
@model OrderGetModel
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>修改订单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="~/common/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="~/common/bootstrap/css/bootstrap.css" media="all">
    <link rel="stylesheet" type="text/css" href="~/common/global.css" media="all">
    <link rel="stylesheet" type="text/css" href="~/css/personal.css" media="all">
</head>
<body class="childrenBody">
    <form class="layui-form ">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label col-lg-1">订单编号:</label>
                <div class="layui-input-block">

                    <input type="hidden" name="Id" value="@Model.Order.Id" />

                    <input type="text" name="Guid" autocomplete="off" class="layui-input layui-disabled" value="@Model.Order.Guid" disabled="disabled">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label col-lg-1">邮政编号:</label>
                <div class="layui-input-block">
                    <input class="layui-input" name="PostEmail" value="@Model.Order.PostEmail" lay-verify="required|PostEmail" placeholder="" type="text">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label col-lg-1">收货人:</label>
                <div class="layui-input-block">
                    <input class="layui-input" name="ReciverName" value="@Model.Order.ReciverName" lay-verify="required" placeholder="" type="text">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label col-lg-1">手机号:</label>
                <div class="layui-input-block">
                    <input class="layui-input" name="PhoneNum" value="@Model.Order.PhoneNum" lay-verify="required|phone" placeholder="" type="text">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label col-lg-1">订单状态:</label>
                <div class="layui-input-block">
                    <select name="StatusId" class="newsLook" lay-filter="StatusId">
                        @foreach (var status in Model.Statues)
                        {
                            <option selected="@(status.Id == Model.Order.StatusId)" value="@status.Id">@status.Name</option>
                        }
                    </select>
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label col-lg-1">付款方式:</label>
                <div class="layui-input-block">
                    <select name="PayWayId" class="newsLook" lay-filter="PayWayId">
                        @foreach (var payWays in Model.PayWays)
                        {
                            <option selected="@(payWays.Id == Model.Order.PayWayId)" value="@payWays.Id">@payWays.Name</option>
                        }
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">付款金额:</label>
                <div class="layui-input-block">
                    <input class="layui-input newsAuthor" value="@Model.Order.Amount" name="Amount" lay-verify="required|price" placeholder="" type="text">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">买家留言:</label>
                <div class="layui-input-block">
                    <input class="layui-input newsAuthor" value="@Model.Order.LeaveWord" name="LeaveWord" lay-verify="required|LeaveWord" placeholder="" type="text">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label col-lg-1">发票类型:</label>
                <div class="layui-input-block">
                    <select name="ReceiptId" class="newsLook" lay-filter="ReceiptId">
                        @foreach (var receipt in Model.Receipts)
                        {
                            <option selected="@(receipt.Id == Model.Order.ReceiptId)" value="@receipt.Id">@receipt.Name</option>
                        }
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label col-lg-1">快递公司:</label>
                <div class="layui-input-block">
                    <select name="ExpressId" class="newsLook" lay-filter="ExpressId">
                        @foreach (var experss in Model.Express)
                        {
                            <option selected="@(experss.Id == Model.Order.ExpressId)" value="@experss.Id">@experss.Name</option>
                        }
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label col-lg-1">下单时间:</label>
                <div class="layui-input-block">
                    <input class="layui-input" lay-verify="required|datetime" value="@Model.Order.CreateDateTime" name="CreateDateTime" id="CreateDateTime" onClick="laydate({elem:this})" type="text">
                </div>
            </div>

        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label col-lg-1">收货地址:</label>
                <div class="layui-input-block">
                    <select name="ProvinceId" class="ProvinceId" lay-filter="ProvinceId">
                        @foreach (var province in Model.Provinces)
                        {
                            <option selected="@(province.Id == Model.ProvinceId)" value="@province.Id">@province.Name</option>
                        }
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label col-lg-1">市:</label>
                <div class="layui-input-block">
                    <select name="CityId" class="CityId" lay-filter="CityId"></select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label col-lg-1">区:</label>
                <div class="layui-input-block">
                    <select name="AreaId" class="AddressId" lay-filter="AddressId"></select>
                </div>
            </div>
        </div>

        <div class="layui-form-item col-lg-5">
            <label class="layui-form-label">详细地址</label>

            <div class="layui-input-block ">
                <textarea name="ReciverAddress" con lay-verify="required|ReciverAddress" placeholder="请填写详细地址" class="layui-textarea">@Model.Order.ReciverAddress</textarea>
            </div>

        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="edit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <script type="text/javascript" src="~/common/laydate.js"></script>
    <script type="text/javascript" src="~/common/layui/layui.all.js"></script>
    <script type="text/javascript">
        var province =@Model.ProvinceId;
        var city =@Model.CityId;
        var area=@Model.AreaId;


        //执行一个laydate实例
        laydate.render({
            elem: '#CreateDateTime', //指定元素
            type: 'datetime',
            format: 'yyyy/MM/dd HH:mm:ss'
        });

        layui.config({
            base: "js/"
        }).use(['form', 'layer', 'jquery', 'layedit'], function () {
            var form = layui.form,
                layer = parent.layer === undefined ? layui.layer : parent.layer,
                laypage = layui.laypage,
                layedit = layui.layedit,
                $ = layui.jquery;


            $(function () {
                getCity(province);
                getArea(city);
            });


            function getCity(provinceId, loadArea) {
                $(".CityId").html("");
                $.ajax({
                    url: "/Order/GetCity",
                    method: "post",
                    dataType: "json",
                    data: { provinceId: provinceId },
                    traditional: true,//这里设置为true
                    success: function (res) {
                        if (res.status == "ok") {


                            $.each(res.data, function (index, value) {
                                if (city == null && index == 0) {
                                    city = value.id;

                                    loadArea != null ? loadArea() : "";

                                    $(".CityId").append("<option selected='selected' value='" + value.id + "'>" + value.name + "</option>");
                                }else if (value.id == city) {
                                    $(".CityId").append("<option selected='selected' value='" + value.id + "'>" + value.name + "</option>");
                                } else {
                                    $(".CityId").append("<option value='" + value.id + "'>" + value.name + "</option>");
                                }

                            });

                            form.render('select');

                        } else {
                            layer.msg("获取城市失败:" + res.errorMsg, {icon: 5, time: 2000});
                        }
                    },
                    error: function () {
                        layer.msg("网络请求失败:" + res.errorMsg, { icon: 5, time: 2000 });
                    }
                });
            }

            function getArea(cityId) {
                $(".AddressId").html("");
                $.ajax({
                    url: "/Order/GetArea",
                    method: "post",
                    dataType: "json",
                    data: { cityId: cityId },
                    traditional: true,//这里设置为true
                    success: function (res) {
                        if (res.status == "ok") {


                            $.each(res.data, function (index, value) {

                                if (area == null && index == 0) {
                                    $(".AddressId").append("<option selected='selected' value='" + value.id + "'>" + value.name + "</option>");
                                }else if (value.id == area) {
                                    $(".AddressId").append("<option selected='selected' value='" + value.id + "'>" + value.name + "</option>");

                                } else {
                                    $(".AddressId").append("<option value='" + value.id + "'>" + value.name + "</option>");
                                }

                            });

                            form.render('select');

                        } else {
                            layer.msg("获取城市失败:" + res.errorMsg, { icon: 5, time: 2000 });
                        }
                    },
                    error: function () {
                        layer.msg("网络请求失败:" + res.errorMsg, { icon: 5, time: 2000 });
                    }
                });
            }


            form.on('select(ProvinceId)', function (data) {
                //获取市
                province = data.value;
                city = null;

                $(".AddressId").html("");
                getCity(province, function () {

                    //获取区
                    area = null;
                    getArea(city);
                });

            });

            form.on('select(CityId)', function (data) {

                city = data.value;
                area = null;
                getArea(city);


            });



            //数据验证
            form.verify({
                username: function (value, item) { //value：表单的值、item：表单的DOM对象
                    if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                        return '用户名不能有特殊字符';
                    }
                    if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                        return '用户名首尾不能出现下划线\'_\'';
                    }
                    if (/^\d+\d+\d$/.test(value)) {
                        return '用户名不能全为数字';
                    }
                },
                price: function (value, item) {
                    if (isNaN(value)) {
                        return '请输入正确的价格';
                    }
                },
                LeaveWord: [/^[\u4E00-\u9FA5A-Za-z0-9_]{0,20}$/, "留言中不能出现特殊字符并且不能多余20个字"],
                ReciverAddress: [/^[\u4E00-\u9FA5A-Za-z0-9_]{0,200}$/, "留言中不能出现特殊字符并且不能多余200个字"],
                PostEmail: [/[1-9]\d{5}(?!\d)/, "请输入正确的邮政编码"],
                //我们既支持上述函数式的方式，也支持下述数组的形式
                //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
                pass: [
                    /^[\S]{6,12}$/
                    , '密码必须6到12位，且不能出现空格'
                ]
            });


            //此处的addNew是38行代码中提交按钮的 lay-filter属性
            form.on("submit(edit)", function (data) {

                var index = top.layer.msg('数据提交中，请稍候', { icon: 16, time: false, shade: 0.8 });

                var formData = $(".layui-form").serialize();    //表单数据

                $.ajax({
                    url: "/Order/Edit",
                    method: "post",
                    dataType: "json",
                    data: formData,
                    traditional: true,//这里设置为true
                    success: function (res) {
                        if (res.status == "ok") {
                            top.layer.close(index);
                            layer.msg("修改成功", {
                                icon: 1, time: 2000, end: function () {
                              
                                    layer.closeAll("iframe");
                                    //刷新父页面
                                    parent.location.reload();
                                }
                            });



                        } else {
                            top.layer.close(index);
                            layer.msg("修改失败:" + res.errorMsg, {
                                icon: 5, time: 2000, end: function () {
                                   
                                    layer.closeAll("iframe");
                                    //刷新父页面
                                    parent.location.reload();
                                }
                            });
                        }
                    },
                    error: function () {
                        top.layer.close(index);
                        layer.msg("网络请求失败", {
                            icon: 5, time: 2000, end: function () {
                              
                                layer.closeAll("iframe");
                                //刷新父页面
                                parent.location.reload();
                            }
                        });
                    }
                });

                return false;
            })

        })

    </script>
</body>
</html>